package com.iwhalecloud.uncc.archiver.impl;

import com.iwhalecloud.uncc.archiver.Archiver;
import com.iwhalecloud.uncc.common.DataSourceHelp;
import com.iwhalecloud.uncc.common.SpringContext;
import com.iwhalecloud.uncc.model.InsCollectServer;
import com.iwhalecloud.uncc.service.ArchiverService;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zq
 * @date 2021/10/20 14:29
 * @description InsCollectServerArchiver
 */
@Slf4j
public class InsCollectServerArchiver implements Archiver {

    private ArchiverService<InsCollectServer> insCollectServerArchiverService =
            (ArchiverService<InsCollectServer>) SpringContext.getContext().getBean("insCollectServerArchiverService");

    private DataSourceHelp dataSourceHelp =
            (DataSourceHelp) SpringContext.getContext().getBean("dataSourceHelp");
    /**
     * 归档 InsCollectServer 关联
     */
    @Override
    public void archive() {
        if (log.isInfoEnabled()) {
            log.info("InsCollectServerArchiver 提交归档任务...");
        }

        dataSourceHelp.getOnlineDatasource()
                .forEach(i->insCollectServerArchiverService.archive(i.getCode()));

    }
}
